*******************************************************************
*Replication code for
*	Article: COVID 19 infection induces higher trust in strangers
*	Journal: PNAS
*	Authors: Diego Gambetta and Davide Morisi
*******************************************************************

*Set working directory
cd "[your working directory]"

*open data
use "Replication\Data\swg_panel_replication", clear

*individual controls
global demo_basic "i.female age ib2.edu4 i.area"

*additional controls
global demo_full2_w1 "i.female age ib2.edu4 i.w1_live_alone ib2.employ1 i.w1_perceived_eco2 i.area"
global demo_full2_w2 "i.female age ib2.edu4 i.w2_live_alone ib2.employ1 i.w2_perceived_eco2 i.area"
global demo_full2_w3 "i.female age ib2.edu4 i.w3_live_alone ib2.employ1 i.w3_perceived_eco2 i.area"
*controlling for region of residence
global demo_region_w1 "i.female age ib2.edu4 i.w1_live_alone ib2.employ1 i.w1_perceived_eco2 i.region2"
global demo_region_w2 "i.female age ib2.edu4 i.w2_live_alone ib2.employ1 i.w2_perceived_eco2 i.region2"
global demo_region_w3 "i.female age ib2.edu4 i.w3_live_alone ib2.employ1 i.w3_perceived_eco2 i.region2"

*municipality controls
global demo_geo "log_pop2018 log_dens2018 male_ratio_dec share65plus_dec employ_rate2018_dec"

*standardized measure of trust
drop st_trust_strangerW1
egen st_trust_strangerW1 = std(trust_stranger)
sum st_trust_strangerW*


*************************
*A. CROSS-SECTIONAL ANALYSIS
*************************

*
*Table A1. Summary statistics

*Wave 1
*trust
sum trust_neighbour trust_police trust_stranger trust_gen [iweight=weight_w1]
*covid measures
sum covid_ind covid_family4 covid_friends4 covid_colleague4 incr_mar_apr2020_w5 [iweight=weight_w1]
*socio-demographics
sum age
fre female w1_live_alone w1_perceived_eco2
ta edu4, gen(edu4_cat)
ta employ1, gen(employ1_cat)
ta area, gen(area_cat)
sum female age edu4_cat* w1_live_alone employ1_cat* w1_perceived_eco2 area_cat* [iweight=weight_w1]
*geographical measures
sum log_pop2018 log_dens2018 male_ratio share65plus employ_rate2018r [iweight=weight_w1]
*table
eststo clear
estpost sum trust_neighbour trust_police trust_stranger trust_gen ///
covid_ind covid_family4 covid_friends4 covid_colleague4 incr_mar_apr2020_w5 ///
female age edu4_cat* w1_live_alone employ1_cat* w1_perceived_eco2 area_cat* ///
log_pop2018 log_dens2018 male_ratio share65plus employ_rate2018r [iweight=weight_w1]
esttab using "~TableA1.rtf", cells("count mean sd min max") replace
*drop created var
drop edu4_cat* employ1_cat* area_cat* 

*Wave 2
*trust
sum w2_trust_neighbour w2_trust_police w2_trust_stranger w2_trust_gen w2_trust_it01 [iweight=weight_w2]
*covid measures
sum w2_covid_ind w2_covid_family4 w2_covid_acq_fr4 w2_covid_col4 incr_sep_oct2020_w5 [iweight=weight_w2]
*other var
sum w2_live_alone w2_perceived_eco2
*table
eststo clear
estpost sum w2_trust_neighbour w2_trust_police w2_trust_stranger w2_trust_gen w2_trust_it01 ///
w2_covid_ind w2_covid_family4 w2_covid_acq_fr4 w2_covid_col4 incr_sep_oct2020_w5 ///
w2_live_alone w2_perceived_eco2 [iweight=weight_w2]
esttab using "~TableA1w2.rtf", title("Wave 2") cells("count mean sd min max") replace

*Wave 3
*trust
sum w3_trust_neighbour w3_trust_police w3_trust_stranger w3_trust_gen w3_trust_it01 [iweight=weight_w3]
*covid measures
sum w3_covid_ind w3_covid_family4 w3_covid_acq_fr4 w3_covid_col4 incr_dec_jan2021_w5 [iweight=weight_w3]
*other var
sum w3_live_alone w3_perceived_eco2
*table
eststo clear
estpost sum w3_trust_neighbour w3_trust_police w3_trust_stranger w3_trust_gen w3_trust_it01 ///
w3_covid_ind w3_covid_family4 w3_covid_acq_fr4 w3_covid_col4 incr_dec_jan2021_w5 ///
w3_live_alone w3_perceived_eco2 [iweight=weight_w3]
esttab using "~TableA1w3.rtf", title("Wave 3") cells("count mean sd min max") replace


*
*Table A2. Correlations between measures of trust (Pearson’s correlations)
fre panel_w1_r
*w1
pwcorr trust_gen trust_neighbour trust_police trust_stranger if panel_w1_r==1, sig obs
pwcorr trust_gen trust_neighbour trust_police trust_stranger pca1_W1 if panel_w1_r==1
pwcorr st_trust_genW1 st_trust_neighbourW1 st_trust_policeW1 st_trust_strangerW1 pca1_W1 if panel_w1_r==1
logit trust_gen trust_neighbour trust_police trust_stranger $demo_basic if panel_w1_r==1
*w2
pwcorr w2_trust_gen w2_trust_neighbour w2_trust_police w2_trust_stranger w2_trust_it01 if panel_w2==1, sig obs
pwcorr w2_trust_gen w2_trust_neighbour w2_trust_police w2_trust_stranger w2_trust_it01 pca1_W2 pca_full1_W2 if panel_w2==1
logit w2_trust_gen w2_trust_neighbour w2_trust_police w2_trust_stranger w2_trust_it01 $demo_basic if panel_w3==1
*w3
pwcorr w3_trust_gen w3_trust_neighbour w3_trust_police w3_trust_stranger w3_trust_it01 if panel_w3==1, sig obs
pwcorr w3_trust_gen w3_trust_neighbour w3_trust_police w3_trust_stranger w3_trust_it01 pca1_W3 pca_full1_W3 if panel_w3==1
logit w3_trust_gen w3_trust_neighbour w3_trust_police w3_trust_stranger w3_trust_it01 $demo_basic if panel_w3==1


*
*Table A3. Exposure to COVID-19 and trust in strangers (Wave 1)
eststo clear
eststo: reg trust_stranger i.covid_ind covid_family4 covid_friends4 covid_colleague4 i.incr_mar_apr2020_quin $demo_basic i.group [pweight=weight_w1]
eststo: reg trust_stranger i.covid_ind covid_family4 covid_friends4 covid_colleague4 i.incr_mar_apr2020_quin $demo_full2_w1 $demo_geo i.group [pweight=weight_w1]
eststo: reg trust_stranger i.covid_ind covid_family4 covid_friends4 covid_colleague4 i.incr_mar_apr2020_quin $demo_region_w1 $demo_geo i.group [pweight=weight_w1]
esttab using "~TableA3.rtf", ///
b(%6.3f) se(%6.3f) starlevels(+ .1 * .05 ** .01 *** .001)  scalars (r2) title("Table A3. Covid & trust - W1") wide compress noeqlines replace
*standardized
reg st_trust_stranger i.covid_ind covid_family4 covid_friends4 covid_colleague4 i.incr_mar_apr2020_quin $demo_basic i.group [pweight=weight_w1]
reg st_trust_stranger i.covid_ind covid_family4 covid_friends4 covid_colleague4 i.incr_mar_apr2020_quin $demo_full2_w1 $demo_geo i.group [pweight=weight_w1]
reg st_trust_stranger i.covid_ind covid_family4 covid_friends4 covid_colleague4 i.incr_mar_apr2020_quin $demo_region_w1 $demo_geo i.group [pweight=weight_w1]

*
*Table A4. Exposure to COVID-19 and trust in strangers (Wave 2)
eststo clear
eststo: reg w2_trust_stranger i.w2_covid_ind_new w2_covid_family4 w2_covid_acq_fr4 w2_covid_col4 i.incr_sep_oct2020_quin $demo_basic i.group [pweight=weight_w2]
eststo: reg w2_trust_stranger i.w2_covid_ind_new w2_covid_family4 w2_covid_acq_fr4 w2_covid_col4 i.incr_sep_oct2020_quin $demo_full2_w2 $demo_geo i.group [pweight=weight_w2]
eststo: reg w2_trust_stranger i.w2_covid_ind_new w2_covid_family4 w2_covid_acq_fr4 w2_covid_col4 i.incr_sep_oct2020_quin $demo_region_w2 $demo_geo i.group [pweight=weight_w2]
esttab using "~TableA4.rtf", ///
b(%6.3f) se(%6.3f) starlevels(+ .1 * .05 ** .01 *** .001)  scalars (r2) title("Table A4. Covid & trust - W2") wide compress noeqlines replace

*
*Table A5. Exposure to COVID-19 and trust in strangers (Wave 3)
eststo clear
eststo: reg w3_trust_stranger i.w3_covid_ind_new w3_covid_family4 w3_covid_acq_fr4 w3_covid_col4 i.incr_dec_jan2021_quin $demo_basic i.group [pweight=weight_w3]
eststo: reg w3_trust_stranger i.w3_covid_ind_new w3_covid_family4 w3_covid_acq_fr4 w3_covid_col4 i.incr_dec_jan2021_quin $demo_full2_w3 $demo_geo i.group [pweight=weight_w3]
eststo: reg w3_trust_stranger i.w3_covid_ind_new w3_covid_family4 w3_covid_acq_fr4 w3_covid_col4 i.incr_dec_jan2021_quin $demo_region_w3 $demo_geo i.group [pweight=weight_w3]
esttab using "~TableA5.rtf", ///
b(%6.3f) se(%6.3f) starlevels(+ .1 * .05 ** .01 *** .001)  scalars (r2) title("Table A5. Covid & trust - W3") wide compress noeqlines replace


*************************
*B. EXPERIMENT ANALYSIS
*************************

*
*Table B1. Balance checks (Wave 1)
eststo clear
eststo: mlogit group i.covid_ind covid_family4 covid_friends4 covid_colleague4 i.incr_mar_apr2020_quin $demo_full2_w1 $demo_geo, b(1)
esttab using "~TableB1.rtf", ///
b(%6.3f) se(%6.3f) starlevels(+ .1 * .05 ** .01 *** .001)  scalars (r2) title("Table B1. Balance checks Wave 1") wide compress noeqlines replace

*
*Table B2. Balance checks (Wave 2)
eststo clear
eststo: mlogit group i.w2_covid_ind_new w2_covid_family4 w2_covid_acq_fr4 w2_covid_col4 i.incr_sep_oct2020_quin $demo_full2_w2 $demo_geo if panel_w2==1, b(1)
esttab using "~TableB2.rtf", ///
b(%6.3f) se(%6.3f) starlevels(+ .1 * .05 ** .01 *** .001)  scalars (r2) title("Table B2. Balance checks Wave 2") wide compress noeqlines replace

*
*Table B3. Balance checks (Wave 3)
eststo clear
eststo: mlogit group i.w3_covid_ind_new w3_covid_family4 w3_covid_acq_fr4 w3_covid_col4 i.incr_dec_jan2021_quin $demo_full2_w3 $demo_geo if panel_w3==1, b(1)
esttab using "~TableB3a.rtf", ///
b(%6.3f) se(%6.3f) starlevels(+ .1 * .05 ** .01 *** .001)  scalars (r2) title("Table B3. Balance checks Wave 3") wide compress noeqlines replace


*
*Table B4. Treatment effects on trust items (W1)
*Panel A. No covariates
eststo clear
eststo: reg trust_stranger i.group 
eststo: reg trust_neighbour i.group 
eststo: reg trust_police i.group 
logit trust_gen i.group
eststo: margin, dydx(group) post 
eststo: reg npca1_W1 i.group
esttab using "~TableB4A.rtf", ///
b(%6.3f) se(%6.3f) starlevels(+ .1 * .05 ** .01 *** .001)  scalars (r2) title("Table B4. panel A") compress noeqlines replace
*Panel B. With covariates
eststo clear
eststo: reg trust_stranger i.group i.covid_ind covid_family4 covid_friends4 covid_colleague4 i.incr_mar_apr2020_quin $demo_full2_w1 $demo_geo
eststo: reg trust_neighbour i.group i.covid_ind covid_family4 covid_friends4 covid_colleague4 i.incr_mar_apr2020_quin $demo_full2_w1 $demo_geo
eststo: reg trust_police i.group i.covid_ind covid_family4 covid_friends4 covid_colleague4 i.incr_mar_apr2020_quin $demo_full2_w1 $demo_geo 
logit trust_gen i.group i.covid_ind covid_family4 covid_friends4 covid_colleague4 i.incr_mar_apr2020_quin $demo_full2_w1 $demo_geo
eststo: margin, dydx(group) post 
eststo: reg npca1_W1 i.group i.covid_ind covid_family4 covid_friends4 covid_colleague4 i.incr_mar_apr2020_quin $demo_full2_w1 $demo_geo
esttab using "~TableB4B.rtf", ///
b(%6.3f) se(%6.3f) starlevels(+ .1 * .05 ** .01 *** .001)  scalars (r2) title("Table B4. panel B") compress noeqlines replace

*Effects on standardized trust in strangers
eststo clear
eststo: reg st_trust_strangerW1 i.group 
eststo: reg st_trust_strangerW1 i.group i.covid_ind covid_family4 covid_friends4 covid_colleague4 i.incr_mar_apr2020_quin $demo_full2_w1 $demo_geo
esttab using "~TableB4_stW1.rtf", ///
b(%6.3f) se(%6.3f) starlevels(+ .1 * .05 ** .01 *** .001)  scalars (r2) title("Table B4. Treatment effects on trust in strangers") wide compress noeqlines replace


*************
*Figure 1. Treatment effects on interpersonal trust (Wave 1)

*Trust in strangers
fre trust_stranger
reg st_trust_strangerW1 i.group
eststo clear
reg trust_stranger i.group
eststo health: margins, dydx(2.group) post
reg trust_stranger i.group
eststo eco: margins, dydx(3.group) post
reg trust_stranger i.group
eststo solid: margins, dydx(4.group) post
*graph
coefplot (health, ciopts(lcolor(navy)) mcolor(navy) msymbol(O) msize(medlarge))  ///
(eco, ciopts(lcolor(maroon)) mcolor(maroon) msymbol(S) msize(medlarge)) ///
(solid, ciopts(lcolor(forest_green)) mcolor(forest_green) msymbol(T) msize(medlarge)), ///
vertical yline(0, lpattern(dash) lcolor(gs10)) ///
level(90 95) graphregion(color(white)) ///
ytitle("Treatment effects on trust compared to control") name(fig1A, replace) ///
xlabel(0.8 "Risk to health" 2 "Risk to livelihood" 3.2 "Solidarity", alternate) ///
title("Trust in strangers") legend(off)

*Trust in neighbours
fre trust_neighbour
eststo clear
reg trust_neighbour i.group
eststo health: margins, dydx(2.group) post
reg trust_neighbour i.group
eststo eco: margins, dydx(3.group) post
reg trust_neighbour i.group
eststo solid: margins, dydx(4.group) post
*graph
coefplot (health, ciopts(lcolor(navy)) mcolor(navy) msymbol(O) msize(medlarge))  ///
(eco, ciopts(lcolor(maroon)) mcolor(maroon) msymbol(S) msize(medlarge)) ///
(solid, ciopts(lcolor(forest_green)) mcolor(forest_green) msymbol(T) msize(medlarge)), ///
vertical yline(0, lpattern(dash) lcolor(gs10)) ///
level(90 95) graphregion(color(white)) ///
ytitle("") name(fig1B, replace) ///
xlabel(0.8 "Risk to health" 2 "Risk to livelihood" 3.2 "Solidarity", alternate) ///
title("Trust in neighbors") legend(off)

*Trust in police
fre trust_police
eststo clear
reg trust_police i.group
eststo health: margins, dydx(2.group) post
reg trust_police i.group
eststo eco: margins, dydx(3.group) post
reg trust_police i.group
eststo solid: margins, dydx(4.group) post
*graph
coefplot (health, ciopts(lcolor(navy)) mcolor(navy) msymbol(O) msize(medlarge))  ///
(eco, ciopts(lcolor(maroon)) mcolor(maroon) msymbol(S) msize(medlarge)) ///
(solid, ciopts(lcolor(forest_green)) mcolor(forest_green) msymbol(T) msize(medlarge)), ///
vertical yline(0, lpattern(dash) lcolor(gs10)) ///
level(90 95) graphregion(color(white)) ///
ytitle("") name(fig1C, replace) ///
xlabel(0.8 "Risk to health" 2 "Risk to livelihood" 3.2 "Solidarity", alternate) ///
title("Trust in police") legend(off)

*Generalized trust
fre trust_gen
eststo clear
logit trust_gen i.group
logit trust_gen i.group, level(90)
margins, dydx(group) level(90)
eststo health: margins, dydx(2.group) post
logit trust_gen i.group
eststo eco: margins, dydx(3.group) post
logit trust_gen i.group
eststo solid: margins, dydx(4.group) post
*graph
coefplot (health, ciopts(lcolor(navy)) mcolor(navy) msymbol(O) msize(medlarge))  ///
(eco, ciopts(lcolor(maroon)) mcolor(maroon) msymbol(S) msize(medlarge)) ///
(solid, ciopts(lcolor(forest_green)) mcolor(forest_green) msymbol(T) msize(medlarge)), ///
vertical yline(0, lpattern(dash) lcolor(gs10)) ///
level(90 95) graphregion(color(white)) ///
ytitle("") name(fig1D, replace) ///
xlabel(0.8 "Risk to health" 2 "Risk to livelihood" 3.2 "Solidarity", alternate) ///
title("Generalized trust") legend(off)

*PCA
fre npca1_W1
eststo clear
reg npca1_W1 i.group
eststo health: margins, dydx(2.group) post
reg npca1_W1 i.group
eststo eco: margins, dydx(3.group) post
reg npca1_W1 i.group
eststo solid: margins, dydx(4.group) post
*graph
coefplot (health, ciopts(lcolor(navy)) mcolor(navy) msymbol(O) msize(medlarge))  ///
(eco, ciopts(lcolor(maroon)) mcolor(maroon) msymbol(S) msize(medlarge)) ///
(solid, ciopts(lcolor(forest_green)) mcolor(forest_green) msymbol(T) msize(medlarge)), ///
vertical yline(0, lpattern(dash) lcolor(gs10)) ///
level(90 95) graphregion(color(white)) ///
ytitle("") name(fig1E, replace) ///
xlabel(0.8 "Risk to health" 2 "Risk to livelihood" 3.2 "Solidarity", alternate) ///
title("PCA (all items)") legend(off)

*combined
graph combine fig1A fig1B fig1C fig1D fig1E, graphregion(color(white))



************
*Table B5. Treatment effects over time

*Wave 2
eststo clear
eststo: reg w2_trust_stranger i.group
eststo: reg w2_trust_stranger i.group i.w2_covid_ind w2_covid_family4 w2_covid_acq_fr4 w2_covid_col4 i.incr_sep_oct2020_quin $demo_full2_w2 $demo_geo
esttab using "~TableB5_W2.rtf", ///
b(%6.3f) se(%6.3f) starlevels(+ .1 * .05 ** .01 *** .001)  scalars (r2) title("Table B5. W2") compress noeqlines replace
*Wave 3
eststo clear
eststo: reg w3_trust_stranger i.group
eststo: reg w3_trust_stranger i.group i.w3_covid_ind w3_covid_family4 w3_covid_acq_fr4 w3_covid_col4 i.incr_dec_jan2021_quin $demo_full2_w3 $demo_geo
esttab using "~TableB5_W3.rtf", ///
b(%6.3f) se(%6.3f) starlevels(+ .1 * .05 ** .01 *** .001)  scalars (r2) title("Table B5. W3") compress noeqlines replace


*
*Table B6. Heterogeneous treatment effects on trust in strangers by individual exposure to COVID-19
eststo clear
*w1
eststo: reg trust_stranger i.group##i.covid_ind
eststo: reg trust_stranger i.group##i.covid_ind covid_family4 covid_friends4 covid_colleague4 i.incr_mar_apr2020_quin $demo_full2_w1 $demo_geo
*w2
eststo: reg w2_trust_stranger i.group##i.w2_covid_ind
eststo: reg w2_trust_stranger i.group##i.w2_covid_ind w2_covid_family4 w2_covid_acq_fr4 w2_covid_col4 i.incr_sep_oct2020_quin $demo_full2_w2 $demo_geo
*w3
eststo: reg w3_trust_stranger i.group##i.w3_covid_ind
eststo: reg w3_trust_stranger i.group##i.w3_covid_ind w3_covid_family4 w3_covid_acq_fr4 w3_covid_col4 i.incr_dec_jan2021_quin $demo_full2_w3 $demo_geo
esttab using "~TableB6.rtf", ///
b(%6.3f) se(%6.3f) starlevels(+ .1 * .05 ** .01 *** .001)  scalars (r2) title("Table B6") compress noeqlines replace



**************************
*
*Table C5. cross lagged panel model
eststo clear
eststo: reg w2_trust_stranger i.covid_ind trust_stranger $demo_basic [pweight=weight_w2]
eststo: reg w2_trust_stranger i.covid_ind trust_stranger $demo_full2_w1 $demo_geo [pweight=weight_w2]

eststo: reg w3_trust_stranger i.w2_covid_ind i.covid_ind w2_trust_stranger trust_stranger  $demo_basic [pweight=weight_w3]
eststo: reg w3_trust_stranger i.w2_covid_ind i.covid_ind w2_trust_stranger trust_stranger  $demo_full2_w2 $demo_geo [pweight=weight_w3]

esttab using "~TableC5.rtf", ///
b(%6.3f) se(%6.3f) starlevels(+ .1 * .05 ** .01 *** .001)  scalars (r2) title("Table C5. Cross-lagged model") compress noeqlines replace

